import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon, QFont
from PyQt5.QtCore import Qt
from gui.main_window import MainWindow

def get_scaled_font(default_font, screen):
    """
    根据屏幕 DPI 调整字体大小
    :param default_font: 默认字体
    :param screen: QScreen 对象
    :return: 调整后的字体
    """
    dpi = screen.logicalDotsPerInch()  # 获取逻辑 DPI
    scale_factor = dpi / 128  # 96 DPI 为标准
    scaled_font = QFont(default_font.family(), int(default_font.pointSize() * scale_factor))
    return scaled_font

if __name__ == "__main__":
    app = QApplication(sys.argv)

    # 启用高 DPI 支持
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)

    # 获取系统默认字体
    # default_font = QApplication.font()
    #
    # # 获取主屏幕 DPI 信息
    # screen = app.primaryScreen()
    # scaled_font = get_scaled_font(default_font, screen)
    #
    # # 应用全局字体
    # app.setFont(scaled_font)

    # 设置全局图标
    app.setWindowIcon(QIcon("assets/icon.ico"))

    # 创建主窗口
    window = MainWindow()
    window.show()

    # 运行应用程序
    sys.exit(app.exec_())
